package org.mat.ipaas.ucenter.service.api.system;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.dto.system.entity.*;
import org.mat.ipaas.ucenter.service.dto.system.vo.SysUserTenantVoDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.tenant.TenantDepartAuthInfoDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.tenant.TenantPackModelDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.tenant.TenantPackUserCountDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.tenant.TenantPackUserDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 租户配置信息
 *
 */
@FeignClient(name = "mat-ipaas-ucenter-service", contextId = "sys-tenant-rest-api")
public interface SysTenantRestAPI {

    /**
     * 获取列表数据
     *
     * @param sysTenantDTO
     * @param pageNo
     * @param pageSize
     * @return
     */
    //@RequiresPermissions("system:tenant:list")
    @RequestMapping(value = "/sys/tenant/list", method = RequestMethod.GET)
    MatApiResponse<Page<SysTenantDTO>> queryPageList(@SpringQueryMap SysTenantDTO sysTenantDTO,
                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);

    /**
     * 获取租户删除的列表
     *
     * @param sysTenantDTO
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/sys/tenant/recycleBinPageList")
    //@RequiresPermissions("system:tenant:recycleBinPageList")
    MatApiResponse<IPage<SysTenantDTO>> recycleBinPageList(@SpringQueryMap SysTenantDTO sysTenantDTO,
                                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);

    /**
     * 添加
     *
     * @param
     * @return
     */
    //@RequiresPermissions("system:tenant:add")
    @RequestMapping(value = "/sys/tenant/add", method = RequestMethod.POST)
    MatApiResponse<SysTenantDTO> add(@RequestBody SysTenantDTO sysTenantDTO);

    /**
     * 编辑
     *
     * @param
     * @return
     */
    //@RequiresPermissions("system:tenant:edit")
    @RequestMapping(value = "/sys/tenant/edit", method = {RequestMethod.POST})
    MatApiResponse<SysTenantDTO> edit(@RequestBody SysTenantDTO tenant);

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    //@RequiresPermissions("system:tenant:delete")
    @RequestMapping(value = "/sys/tenant/delete", method = {RequestMethod.DELETE})
    MatApiResponse<?> delete(@RequestParam(name = "id", required = true) String id);

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    //@RequiresPermissions("system:tenant:deleteBatch")
    @RequestMapping(value = "/sys/tenant/deleteBatch", method = RequestMethod.DELETE)
    MatApiResponse<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids);

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/sys/tenant/queryById", method = RequestMethod.GET)
    MatApiResponse<SysTenantDTO> queryById(@RequestParam(name = "id", required = true) String id);


    /**
     * 查询有效的 租户数据
     *
     * @return
     */
    //@RequiresPermissions("system:tenant:queryList")
    @RequestMapping(value = "/sys/tenant/queryList", method = RequestMethod.GET)
    MatApiResponse<List<SysTenantDTO>> queryList(@RequestParam(name = "ids", required = false) String ids);

    /**
     * 产品包分页列表查询
     *
     * @param sysTenantPackDTO
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @GetMapping(value = "/sys/tenant/packList")
    //@RequiresPermissions("system:tenant:packList")
    MatApiResponse<IPage<SysTenantPackDTO>> queryPackPageList(SysTenantPackDTO sysTenantPackDTO,
                                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                              @RequestParam HttpServletRequest req);

    /**
     * 创建租户产品包
     *
     * @param sysTenantPackDTO
     * @return
     */
    @PostMapping(value = "/sys/tenant/addPackPermission")
    //@RequiresPermissions("system:tenant:add:pack")
    MatApiResponse<String> addPackPermission(@RequestBody SysTenantPackDTO sysTenantPackDTO);

    /**
     * 创建租户产品包
     *
     * @param sysTenantPackDTO
     * @return
     */
    @PutMapping(value = "/sys/tenant/editPackPermission")
    //@RequiresPermissions("system:tenant:edit:pack")
    MatApiResponse<String> editPackPermission(@RequestBody SysTenantPackDTO sysTenantPackDTO);

    /**
     * 批量删除用户菜单
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/sys/tenant/deletePackPermissions")
    //@RequiresPermissions("system:tenant:delete:pack")
    MatApiResponse<String> deletePackPermissions(@RequestParam(value = "ids") String ids);


    //===========【低代码应用，前端专用接口 —— 加入限制只能维护和查看自己拥有的租户】==========================================================

    /**
     * 查询当前用户的所有有效租户【低代码应用专用接口】
     *
     * @return
     */
    @RequestMapping(value = "/sys/tenant/getCurrentUserTenant", method = RequestMethod.GET)
    MatApiResponse<Map<String, Object>> getCurrentUserTenant();

    /**
     * 邀请用户【低代码应用专用接口】
     *
     * @param ids
     * @param phone
     * @return
     */
    @PutMapping("/sys/tenant/invitationUserJoin")
    //@RequiresPermissions("system:tenant:invitation:user")
    MatApiResponse<String> invitationUserJoin(@RequestParam("ids") String ids, @RequestParam("phone") String phone);

    /**
     * 获取用户列表数据【低代码应用专用接口】
     *
     * @param sysUserDTO
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @RequestMapping(value = "/sys/tenant/getTenantUserList", method = RequestMethod.GET)
    //@RequiresPermissions("system:tenant:user:list")
    MatApiResponse<IPage<SysUserDTO>> getTenantUserList(SysUserDTO sysUserDTO,
                                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                        @RequestParam(name = "userTenantId") String userTenantId,
                                                        @RequestParam HttpServletRequest req);

    /**
     * 请离用户租户【低代码应用专用接口】
     *
     * @param userIds
     * @param tenantId
     * @return
     */
    @PutMapping("/sys/tenant/leaveTenant")
    //@RequiresPermissions("system:tenant:leave")
    MatApiResponse<String> leaveTenant(@RequestParam("userIds") String userIds,
                                       @RequestParam("tenantId") String tenantId);

    /**
     * 编辑（只允许修改自己拥有的租户）【低代码应用专用接口】
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/sys/tenant/editOwnTenant", method = {RequestMethod.POST})
    MatApiResponse<SysTenantDTO> editOwnTenant(@RequestBody SysTenantDTO tenant,
                                               @RequestParam HttpServletRequest req);

    /**
     * 创建租户并且将用户保存到中间表【低代码应用专用接口】
     *
     * @param sysTenantDTO
     */
    @PostMapping("/sys/tenant/saveTenantJoinUser")
    MatApiResponse<Integer> saveTenantJoinUser(@RequestBody SysTenantDTO sysTenantDTO);

    /**
     * 加入租户通过门牌号【低代码应用专用接口】
     *
     * @param sysTenantDTO
     */
    @PostMapping("/sys/tenant/joinTenantByHouseNumber")
    MatApiResponse<Integer> joinTenantByHouseNumber(@RequestBody SysTenantDTO sysTenantDTO);

    //update-begin---author:wangshuai ---date:20230107  for：[QQYUN-3725]申请加入租户，审核中状态增加接口------------

    /**
     * 分页获取租户用户数据(vue3用户租户页面)【低代码应用专用接口】
     *
     * @param pageNo
     * @param pageSize
     * @param userTenantStatus
     * @param type
     * @return
     */
    @GetMapping("/sys/tenant/getUserTenantPageList")
    //@RequiresPermissions("system:tenant:tenantPageList")
    MatApiResponse<Page<SysUserTenantVoDTO>> getUserTenantPageList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                    @RequestParam(name = "userTenantStatus") String userTenantStatus,
                                                                    @RequestParam(name = "type", required = false) String type,
                                                                    @SpringQueryMap SysUserDTO sysUserDTO);

    /**
     * 通过用户id获取租户列表【低代码应用专用接口】
     *
     * @param userTenantStatus 关系表的状态
     * @return
     */
    @GetMapping("/sys/tenant/getTenantListByUserId")
    //@RequiresPermissions("system:tenant:getTenantListByUserId")
    MatApiResponse<List<SysUserTenantVoDTO>> getTenantListByUserId(@RequestParam(name = "userTenantStatus", required = false) String userTenantStatus);

    /**
     * 更新用户租户关系状态【低代码应用专用接口】
     */
    @PutMapping("/sys/tenant/updateUserTenantStatus")
    //@RequiresPermissions("system:tenant:updateUserTenantStatus")
    MatApiResponse<String> updateUserTenantStatus(@RequestBody SysUserTenantDTO userTenant);

    /**
     * 注销租户【低代码应用专用接口】
     *
     * @param sysTenantDTO
     * @return
     */
    @PutMapping("/sys/tenant/cancelTenant")
    //@RequiresPermissions("system:tenant:cancelTenant")
    MatApiResponse<String> cancelTenant(@RequestBody SysTenantDTO sysTenantDTO, @RequestParam HttpServletRequest request);
    //update-end---author:wangshuai ---date:20230107  for：[QQYUN-3725]申请加入租户，审核中状态增加接口------------

    /**
     * 获取租户用户不同状态下的数量【低代码应用专用接口】
     *
     * @return
     */
    @GetMapping("/sys/tenant/getTenantStatusCount")
    MatApiResponse<Long> getTenantStatusCount(@RequestParam(value = "status", defaultValue = "1") String status,
                                              @RequestParam HttpServletRequest req);

    /**
     * 用户取消租户申请【低代码应用专用接口】
     *
     * @param tenantId
     * @return
     */
    @PutMapping("/sys/tenant/cancelApplyTenant")
    MatApiResponse<String> cancelApplyTenant(@RequestParam("tenantId") String tenantId);

    //===========【低代码应用，前端专用接口 —— 加入限制只能维护和查看自己拥有的租户】==========================================================

    /**
     * 彻底删除租户
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/sys/tenant/deleteLogicDeleted")
    //@RequiresPermissions("system:tenant:deleteTenantLogic")
    MatApiResponse<String> deleteTenantLogic(@RequestParam("ids") String ids);

    /**
     * 还原删除的租户
     *
     * @param ids
     * @return
     */
    @PutMapping("/sys/tenant/revertTenantLogic")
    //@RequiresPermissions("system:tenant:revertTenantLogic")
    MatApiResponse<String> revertTenantLogic(@RequestParam("ids") String ids);

    /**
     * 退出租户【低代码应用专用接口】
     *
     * @param sysTenantDTO
     * 
     * @return
     */
    @DeleteMapping("/sys/tenant/exitUserTenant")
    MatApiResponse<String> exitUserTenant(@RequestBody SysTenantDTO sysTenantDTO, @RequestParam HttpServletRequest request);

    /**
     * 变更租户拥有者【低代码应用专用接口】
     *
     * @param userId
     * @return
     */
    @PostMapping("/sys/tenant/changeOwenUserTenant")
    MatApiResponse<String> changeOwenUserTenant(@RequestParam("userId") String userId);

    /**
     * 邀请用户到租户,通过手机号匹配 【低代码应用专用接口】
     *
     * @param phone
     * @return
     */
    @PostMapping("/sys/tenant/invitationUser")
    MatApiResponse<String> invitationUser(@RequestParam(name = "phone") String phone);


    /**
     * 获取 租户产品包-3个默认admin的人员数量
     *
     * @param tenantId
     * @return
     */
    @GetMapping("/sys/tenant/loadAdminPackCount")
    MatApiResponse<List<TenantPackUserCountDTO>> loadAdminPackCount(@RequestParam("tenantId") Integer tenantId);

    /**
     * 查询租户产品包信息
     *
     * @param packModel
     * @return
     */
    @GetMapping("/sys/tenant/getTenantPackInfo")
    MatApiResponse<TenantPackModelDTO> getTenantPackInfo(TenantPackModelDTO packModel);


    /**
     * 添加用户和产品包的关系数据
     *
     * @param sysTenantPackUserDTO
     * @return
     */
    @PostMapping("/sys/tenant/addTenantPackUser")
    MatApiResponse<?> addTenantPackUser(@RequestBody SysTenantPackUserDTO sysTenantPackUserDTO);

    /**
     * 从产品包移除用户
     *
     * @param sysTenantPackUserDTO
     * @return
     */
    @PutMapping("/sys/tenant/deleteTenantPackUser")
    MatApiResponse<?> deleteTenantPackUser(@RequestBody SysTenantPackUserDTO sysTenantPackUserDTO);


    /**
     * 修改申请状态
     *
     * @param sysTenantDTO
     * @return
     */
    @PutMapping("/sys/tenant/updateApplyStatus")
    MatApiResponse<?> updateApplyStatus(@RequestBody SysTenantDTO sysTenantDTO);


    /**
     * 获取产品包人员申请列表
     *
     * @param tenantId
     * @return
     */
    @GetMapping("/sys/tenant/getTenantPackApplyUsers")
    MatApiResponse<?> getTenantPackApplyUsers(@RequestParam("tenantId") Integer tenantId);

    /**
     * 个人 申请成为管理员
     *
     * @param sysTenantPackUserDTO
     * @return
     */
    @PostMapping("/sys/tenant/doApplyTenantPackUser")
    MatApiResponse<?> doApplyTenantPackUser(@RequestBody SysTenantPackUserDTO sysTenantPackUserDTO);

    /**
     * 申请通过 成为管理员
     *
     * @param sysTenantPackUserDTO
     * @return
     */
    @PutMapping("/sys/tenant/passApply")
    MatApiResponse<?> passApply(@RequestBody SysTenantPackUserDTO sysTenantPackUserDTO);

    /**
     * 拒绝申请 成为管理员
     *
     * @param sysTenantPackUserDTO
     * @return
     */
    @PutMapping("/sys/tenant/deleteApply")
    MatApiResponse<?> deleteApply(@RequestBody SysTenantPackUserDTO sysTenantPackUserDTO);


    /**
     * 进入应用组织页面 查询租户信息及当前用户是否有 管理员的权限--
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/sys/tenant/queryTenantAuthInfo", method = RequestMethod.GET)
    MatApiResponse<TenantDepartAuthInfoDTO> queryTenantAuthInfo(@RequestParam(name = "id", required = true) String id);

    /**
     * 获取产品包下的用户列表(分页)
     *
     * @param tenantId
     * @param packId
     * @param status
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/sys/tenant/queryTenantPackUserList")
    MatApiResponse<IPage<TenantPackUserDTO>> queryTenantPackUserList(@RequestParam("tenantId") String tenantId,
                                                                     @RequestParam("packId") String packId,
                                                                     @RequestParam("status") Integer status,
                                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);
}
